//编辑基本简历
import React, { Component } from 'react';
import {
    View,
    Text,
    TextInput,
    TouchableOpacity,
    ScrollView,
} from 'react-native';

import { posedit_Style as styles1 } from '../../../../../styles';
import { rcentereditStyle as styles } from '../../../../../styles';
import Icon from 'react-native-vector-icons/Ionicons';
import ChooseUtil from '../../../../util/chooseUtil';
import Timeutil from '../../../../util/newtimeUtil';


var Dimensions = require('Dimensions');
var width = Dimensions.get('window').width;


export default class Rtedittwo extends Component {

    constructor(props) {
        super(props);
        this.state = {
            resume: {},
        }
    };

    //加载后渲染页面
    componentDidMount() {
        if (!this.state.resume.resumeId && this.props.resume.resumeId) {
            this.setState({ resume: this.props.resume })
        }
    }

    componentDidUpdate() {
        if (!this.state.resume.resumeId && this.props.resume.resumeId) {
            this.setState({ resume: this.props.resume });
        }
    }

    render() {
        return (
            <View style={{flex:1,backgroundColor:'#ffffff'}}>
                <View style={[styles1.rtopin, {
                    width: width * 1,
                    elevation: 5,
                    shadowColor: 'black',
                    shadowOpacity: 1,
                    shadowRadius: 5
                }]}>

                    <TouchableOpacity activeOpacity={1} style={styles1.rtopicon1} onPress={() => { this.props.navigation.goBack() }}>
                        <Icon
                            name={'ios-arrow-back'}
                            size={25}
                            color={'#ffffff'} />
                    </TouchableOpacity>
                    <Text style={styles1.rtoptext}>基本信息</Text>
                    <TouchableOpacity style={styles1.rtoptextout} activeOpacity={1}
                        onPress={() => {
                            const r = {
                                resumeId: this.state.resume.resumeId,
                                memberId: this.state.resume.memberId,
                                resumeName: this.state.resume.resumeName,
                                resumeSex: this.state.resume.resumeSex,
                                resumeBirth: this.state.resume.resumeBirth,
                                resumeMarriage: this.state.resume.resumeMarriage,
                                resumePosition: this.state.resume.resumePosition,
                                resumeWorkinglife: this.state.resume.resumeWorkinglife,
                                fields: this.state.resume.fields,
                                resumeState: this.state.resume.resumeState,
                                resumeWorkspace: this.state.resume.resumeWorkspace,
                                resumePhone: this.state.resume.resumePhone,
                                resumeEmail: this.state.resume.resumeEmail,
                            }
                            this.props.actions.UpdateResumeAction(r);
                            this.props.navigation.goBack();
                        }}>
                        <Text style={styles1.rtoptext2}>保存</Text>
                    </TouchableOpacity>
                </View >

                <ScrollView style={styles.rout}>
                    {/* 姓名 */}
                    <View style={styles.rmall}>
                        <Text style={styles.rtxt}>真实姓名</Text>
                        <TextInput
                            defaultValue={this.state.resume.resumeName}
                            style={[styles.inputname, { width: width * 0.7 }]}
                            underlineColorAndroid="transparent"
                            onChangeText={this.resumeName.bind(this)}
                        />
                    </View>

                    {/* 性别 */}
                    <View style={styles.rmall}>
                        <Text style={styles.rtxt}>性别</Text>
                        <View style={styles.rsex}>
                            <TouchableOpacity style={styles.rsk} activeOpacity={1} onPress={() => { this.choose(1) }}>
                                {this.state.resume.resumeSex == 1 ? <Text style={styles.rsk2}>
                                    <Icon
                                        name={'md-checkmark'}
                                        size={18}
                                        color={'#fff'} />
                                </Text> : <Text style={styles.rsk}></Text>}
                            </TouchableOpacity>
                            <Text style={styles.sexin}>男</Text>

                            <TouchableOpacity style={styles.rsk} activeOpacity={1} onPress={() => { this.choose(2) }}>
                                {this.state.resume.resumeSex == 2 ? <Text style={styles.rsk2}>
                                    <Icon
                                        name={'md-checkmark'}
                                        size={18}
                                        color={'#fff'} />
                                </Text> : <Text style={styles.rsk}></Text>}
                            </TouchableOpacity>
                            <Text style={styles.sexin2}>女</Text>
                        </View>
                    </View>

                    {/* 出生年份 */}
                    <View style={styles.rmall}>
                        <Text style={styles.rtxt}>出生年份</Text>
                        <Timeutil
                            function={this.resumeBirth.bind(this)}
                            time={this.state.resume.resumeBirth}
                        />
                    </View>


                    {/* 婚姻状况 */}
                    <View style={styles.rmall}>
                        <Text style={styles.rtxt}>婚姻状况</Text>
                        <View style={styles.rsex}>
                            <TouchableOpacity style={styles.rsk} activeOpacity={1} onPress={() => { this.resumeMarriage(0) }}>
                                {this.state.resume.resumeMarriage == 0 ? <Text style={styles.rsk2}>
                                    <Icon
                                        name={'md-checkmark'}
                                        size={18}
                                        color={'#fff'} />
                                </Text> : <Text style={styles.rsk}></Text>}
                            </TouchableOpacity>
                            <Text style={styles.sexin}>未婚</Text>

                            <TouchableOpacity style={styles.rsk} activeOpacity={1} onPress={() => { this.resumeMarriage(1) }}>
                                {this.state.resume.resumeMarriage == 1 ? <Text style={styles.rsk2}>
                                    <Icon
                                        name={'md-checkmark'}
                                        size={18}
                                        color={'#fff'} />
                                </Text> : <Text style={styles.rsk}></Text>}
                            </TouchableOpacity>
                            <Text style={styles.sexin}>已婚</Text>

                            <TouchableOpacity style={styles.rsk} activeOpacity={1} onPress={() => { this.resumeMarriage(2) }}>
                                {this.state.resume.resumeMarriage == 2 ? <Text style={styles.rsk2}>
                                    <Icon
                                        name={'md-checkmark'}
                                        size={18}
                                        color={'#fff'} />
                                </Text> : <Text style={styles.rsk}></Text>}
                            </TouchableOpacity>
                            <Text style={styles.sexin2}>保密</Text>
                        </View>
                    </View>

                    {/* 职位名称 */}
                    <View style={styles.rmall}>
                        <Text style={styles.rtxt}>职位名称</Text>
                        <TextInput
                            style={[styles.inputname, { width: width * 0.7 }]}
                            underlineColorAndroid="transparent"
                            defaultValue={this.state.resume.resumePosition}
                            onChangeText={this.resumePosition.bind(this)}
                        />
                    </View>

                    {/* 工作年份 */}
                    <View style={styles.rmall}>
                        <Text style={styles.rtxt}>工作年份</Text>
                        <ChooseUtil ref="chooseUtil" rollback={this.go.bind(this)} />
                        <TouchableOpacity onPress={() => { this.show2() }} activeOpacity={1}
                            style={[styles.rchooseout, { width: width * 0.7 }]}>
                            <Text style={styles.rchoose}>{this._resumeWorkinglife(this.state.resume.resumeWorkinglife)}</Text>
                        </TouchableOpacity>
                    </View>

                    <View style={styles.rmall}>
                        <Text style={styles.rtxt}>当前行业</Text>
                        <TouchableOpacity
                            style={[styles.rchooseout, { width: width * 0.7 }]} activeOpacity={1}
                            onPress={() => {
                                this.props.navigation.navigate('Trade', { Type: 2, 'rollback': this.setHy.bind(this), list: this.state.resume.fields })
                            }}>
                            <Text style={styles.rchoose}>
                                {this.fieldName(this.state.resume.fields, 3)}
                            </Text>
                        </TouchableOpacity>
                    </View>


                    {/* 当前状态 */}
                    <View style={styles.rmall}>
                        <Text style={styles.rtxt}>当前状态</Text>
                        <ChooseUtil ref="chooseUtil" rollback={this.go.bind(this)} />
                        <TouchableOpacity onPress={() => { this.show() }} activeOpacity={1}
                            style={[styles.rchooseout, { width: width * 0.7 }]}>
                            <Text style={styles.rchoose}>{this._resumeState(this.state.resume.resumeState)}</Text>
                        </TouchableOpacity>

                    </View>

                    <View style={styles.rmall}>
                        <Text style={styles.rtxt}>当前城市</Text>
                        <TouchableOpacity style={[styles.rchooseout, { width: width * 0.7 }]} activeOpacity={1}
                            onPress={() => {
                                this.props.navigation.navigate('cityList',
                                    { 'callback': this.resumeWorkspace.bind(this) });
                            }}>
                            <Text style={styles.rchoose}>
                                {this.state.resume.resumeWorkspace}
                            </Text>
                        </TouchableOpacity>
                    </View>

                    {/* 手机 */}
                    <View style={styles.rmall}>
                        <Text style={styles.rtxt}>手机号</Text>
                        <TextInput
                            style={[styles.inputname, { width: width * 0.7 }]}
                            underlineColorAndroid="transparent"
                            defaultValue={this.state.resume.resumePhone}
                            onChangeText={this.resumePhone.bind(this)}
                        />
                    </View>

                    {/* 邮箱 */}
                    <View style={styles.rmall}>
                        <Text style={styles.rtxt}>邮箱</Text>
                        <TextInput
                            style={[styles.inputname, { width: width * 0.7 }]}
                            underlineColorAndroid="transparent"
                            defaultValue={this.state.resume.resumeEmail}
                            onChangeText={this.resumeEmail.bind(this)}
                        />
                    </View>
                </ScrollView >
            </View >

        )
    }


    //经营领域
    fieldName(List, sl) {
        var data = {
            cont: List
        }
        var arr = '';
        if (data.cont != undefined) {
            var s = 1;
            var length = data.cont.length;
            for (var i = 0; i < data.cont.length; i++) {
                if (data.cont[i].fieldType == '2' && s <= sl) {
                    arr += data.cont[i].fieldName + '/';
                    ++s;
                }
            }
            if (arr.endsWith('/')) {
                arr = arr.substr(0, arr.length - 1);
            }
        }
        return arr;
    }

    setHy(val, type) {
        for (let i = 0; i < this.state.resume.fields.length; i++) {
            if (this.state.resume.fields[i].fieldType == type) {
                this.state.resume.fields.splice(i, 1);
                i = -1;
            }
        }
        const resume = this.state.resume;
        resume.fields = resume.fields.concat(val);
        this.setState({
            resume: resume
        })
    }

    choose(a) {
        const resume = this.state.resume;
        resume.resumeSex = a;
        this.setState({ resume: resume });
    }

    resumeMarriage(a) {
        const resume = this.state.resume;
        resume.resumeMarriage = a;
        this.setState({ resume: resume });
    }

    goTo(name) {
        this.props.navigation.navigate(name);
    }

    show() {
        this.refs.chooseUtil.initPicker("state");
        this.refs.chooseUtil.picker.show();
        this.refs.chooseUtil.setState({
            isModal: true
        })
    }

    show2() {
        this.refs.chooseUtil.initPicker("time");
        this.refs.chooseUtil.picker.show();
        this.refs.chooseUtil.setState({
            isModal: true
        })
    }

    go(key) {
        //时间插件确认回调
        if (key.type == 'time') {
            this.resumeWorkinglife(key.data);
        } else if (key.type == 'state') {
            this.resumeState(key.data);
        }
    }

    resumeName(a) {
        const resume = this.state.resume;
        resume.resumeName = a;
        this.setState({ resume: resume });
    }

    //出生年月
    resumeBirth(a) {
        const resume = this.state.resume;
        resume.resumeBirth = a;
        this.setState({ resume: resume });
    }

    //工作年份
    resumeWorkinglife(a) {
        const resume = this.state.resume;
        resume.resumeWorkinglife = a;
        this.setState({ resume: resume });
    }
    //工作年份
    _resumeWorkinglife(a) {
        let str = '选择';
        if (a) {
            return a;
        } else {
            return str;
        }
    }

    //当前职位
    resumePosition(a) {
        const resume = this.state.resume;
        resume.resumePosition = a;
        this.setState({ resume: resume });
    }

    //当前城市
    resumeWorkspace(a) {
        const resume = this.state.resume;
        resume.resumeWorkspace = a;
        this.setState({ resume: resume });
    }

    //手机
    resumePhone(a) {
        const resume = this.state.resume;
        resume.resumePhone = a;
        this.setState({ resume: resume });
    }

    //邮箱
    resumeEmail(a) {
        const resume = this.state.resume;
        resume.resumeEmail = a;
        this.setState({ resume: resume });
    }

    //当前状态
    resumeState(a) {
        const resume = this.state.resume;
        resume.resumeState = a;
        this.setState({ resume: resume });
    }
    //当前状态
    _resumeState(a) {
        let str = '';
        if (a == '0') {
            str = '未工作';
        } else if (a == '1') {
            str = '在职，看看新机会';
        } else if (a == '2') {
            str = '离职，正在找工作';
        } else if (a == '3') {
            str = '在职，暂无跳槽打算';
        } else if (a == '4') {
            str = '在职，急寻新工作';
        } else {
            str = '选择';
        }
        return str;
    }
}
